using Pkg
Pkg.add("EcologicalNetworksDynamics")This section of the tutorials initiates you into using the Bioenergetic Food Web Model.
Getting the Julia Package
FOR ALL USERS AS OF JUNE 2023
Navigate to the shared google drive in Chrome or your browser: BEFWM2Access.
Now, choose to Download the EcologicalNetworksDynamics.jl-dev file. Make sure it’s the -dev file. It will form a zipped folder and put it in your Downloads folder.
After this, double click the zipped folder in Downloads to get the original folder.
Then, you can drag EcologicalNetworksDynamics.jl-dev from the Downlads folder to your Documents folder on your computer (this is not google drive…)
In the Julia REPL, type
using Pkg
Then, enter the package management zone by typing ] Finally enter this detail.
Mac: dev ~/Documents/EcologicalNetworksDynamics.jl-dev
PC dev C:/Users/YOURUSERNAME/Documents/EcologicalNetworksDynamics.jl-dev
Now go to the section ## Setting Up to Use the Ecological Networks Dynamics modelling
DO NOT USE - Currently Not Available for Guest Users - DO NOT USE
Navigate to the GitHub location for the BioEnergetic Model.
It should look like this:
Then download to your Documents Folder the package.
Once this folder is unzipped in your Documents Folder, you can install it using Pkg.develop.
Setting Up to Use the Ecological Networks Dynamics modelling
And now, you are ready to construct a script using the modelling tools!
## My first BEFW Modelling
## Packages I need
using DataFrames, Plots, Random, Distributions
using EcologicalNetworksDynamics
## Time to do some Experiments!Using the Julia Package
Preamble: The Bioenergetic Food Web.
It is very worth pausing for a moment and visting this paper by Dr. Eva Delmas. It describes the BioEnergetic Food Web Model, provides some history of the model, and also showcases how the original Julia version of the model worked. This section of the tutorials is designed to introduce a newer, faster and more flexible version of the Julia package.
A very basic interpretation of the model is as follows:
- The model is a model of biomass dynamics, not numbers of indiduals.
- The model is comprised of an equation for plants (producers) an equation for consumers (herbivores, predators).
- Plants have traits that make their biomass grow and sets their carrying capacity; they are eaten by consumers via an equation describing a functional response. To link to ecology courses you have, this can be logistic growth for the plant and a type II functional response.
- Consumer have three sets of traits. One is metabolism, which is a rate that describes losses of biomass due to, well, metabolism! The second set of traits correspond to the functional response - for example describing attack rates and handling times of prey items. The third corresponds to the numerical response, or the conversion of biomass they eat into new biomass (e.g. babies)
- We can make complex networks and systems of these equations by letting many of these paramters scale with body size via the rules of allometry and the Metabolic Theory of Ecology. This trick expands the two equations to n = number of species when we provide the toolbox with a list of species biomasses.
- Embedded in this process are rules about how to distribute species of different sizes across trophic levels, so that we end up with predators, omnivores, herbivores and plants. We can also designate the body size relationships for different groups of organisms, like producers, invertebrates, endothermic vertebrates and ectothermic vertebrates.
- Once we’ve done this, we can simulate the biomass dynamics of complext communities. And we can summarise things like changes in biodiversity (number of species), stability (coefficient of variation of the time series) and anything about the biomass of species, trophic levels or the community!
Preamble: Setup
One of main advantages of running food web models in Julia is that simulations are fast and can be readily stored in your active project. With this in mind, make a new folder in your project called out_objects (right click > New Folder).
A first run of the Ecological Network Dynamics model (BEFW)
There are four major steps when running the BioEnergetic Food Web model in Julia. These should be familiar from our introduction to the DifferentialEquations package:
- Generate an initial food web network
- Set the parameters for each species in the network to generate the equations
- Simulate the network and equations
- Explore output and plot
While in the previous example with Differential Equations we assumed a simple 2-species network, one of the new activities here is to take advantage of a rich history of theory and tools to construct species rich networks with appropriate structural properties, such as connectance/complexity and levels of generalism/specialism and things the number of trophic levels and a body size distribtion of the species across trophic levels.
Step 1: generate an initial network
Here we make a foodweb, actually, a food chain, from an adjacency matrix with the FoodWeb method.
A = [0 0 0; 1 0 0; 0 1 0] # 1 basal producer ⋅ Species 2 eats 1 ⋅ Species 3 eats 2
foodweb = Foodweb(A)blueprint for Foodweb with 2 trophic links:
A: 3×3 SparseArrays.SparseMatrixCSC{Bool, Int64} with 2 stored entries:
⋅ ⋅ ⋅
1 ⋅ ⋅
⋅ 1 ⋅
Step 2: Generate the model parameters
Once the foodweb is created, the next step is to attribute values to the model parameters. This can be simply done by calling the method ModelParameters with foodweb as an argument.
# construct the equations and fixed parameters
# see below for body size dependent parameters etc
params = default_model(foodweb)Model (alias for EcologicalNetworksDynamics.Framework.System{<inner parms>}) with 17 components:
- Species: 3 (:s1, :s2, :s3)
- Foodweb: 2 links
- Body masses: [1.0, 10.0, 100.0]
- Metabolic classes: [:producer, :invertebrate, :invertebrate]
- GrowthRate: [1.0, ·, ·]
- Carrying capacity: [1.0, ·, ·]
- ProducersCompetition: 1.0
- LogisticGrowth
- Efficiency: 0.45 to 0.85.
- MaximumConsumption: [·, 8.0, 8.0]
- Hill exponent: 2.0
- Consumers preferences: 1.0
- Intra-specific interference: [·, ·, ·]
- Half-saturation density: [·, 0.5, 0.5]
- BioenergeticResponse
- Metabolism: [0.0, 0.1765751761097696, 0.09929551852928711]
- Mortality: [0.0, 0.0, 0.0]
Step 3: Simulate biomass dynamics
Everything is ready to run the simulation, which can be simply done by calling simulate with the model parameters (params) and a vector species’ initial biomass (B0).
# create body sizes for each species
B0 = [0.5, 0.5, 0.5]
# specify number of time steps
t = 300
# use simulate function
# builds equations and uses DiffEq to run them!
sim = simulate(params, B0, t)retcode: Success
Interpolation: 3rd order Hermite
t: 33-element Vector{Float64}:
0.0
0.09897459745999541
0.3256687683889645
0.6036572540169998
0.9535840860595708
1.3571827128589524
1.8436022477468748
2.4431683104636566
3.2787094666049685
4.180948990477836
5.218130761305353
6.370503477796859
7.688200413884961
⋮
29.828190678129975
35.18211632138491
41.2413663334338
46.900221822131414
51.765364733721995
60.4281642373559
68.2984981354123
79.42658066975167
95.47519096932528
121.85181085318672
178.22682258005116
300.0
u: 33-element Vector{Vector{Float64}}:
[0.5, 0.5, 0.5]
[0.4509091977725071, 0.5009280849553066, 0.514994330697944]
[0.36554322889989416, 0.48803610103762407, 0.5505819753694492]
[0.30176957374113833, 0.4513530874665624, 0.5941900447468553]
[0.26184669180007974, 0.3908311525761556, 0.6441298047192365]
[0.24640602021587787, 0.32217853088430115, 0.6891813154400608]
[0.25078824814388134, 0.25639318936844174, 0.7228571421221244]
[0.27483200612793973, 0.20314200244282063, 0.7391069884604172]
[0.3249885596667774, 0.1652585923904024, 0.7349861611152881]
[0.3828799423194033, 0.1520423806219449, 0.7166152017012525]
[0.4335150341478857, 0.15580099097253053, 0.6935889647086523]
[0.4564472955157229, 0.17019544866289674, 0.6752228345740026]
[0.44893900490266486, 0.18574115006935055, 0.6668744042390637]
⋮
[0.4183264478135517, 0.188338163904122, 0.6566459771617627]
[0.4177953342178679, 0.18852096117581316, 0.6548958443451318]
[0.4172816583591804, 0.1886824876327278, 0.6535404175593097]
[0.41673424766186035, 0.18895448911623808, 0.652658671813466]
[0.4167559738829887, 0.18919973544923865, 0.6519419832516294]
[0.4168602353298981, 0.18875332345956014, 0.6514619549308169]
[0.41666236928320605, 0.18897698938563118, 0.6510490503911017]
[0.41661317008126286, 0.1889386664161753, 0.6508016975340619]
[0.41654453295965616, 0.18897638235291273, 0.6506280671336628]
[0.4165296544432, 0.1889806799000762, 0.6505503523364656]
[0.41652380885769374, 0.18898234025988156, 0.6505368938712377]
[0.4165244291790643, 0.1889822096193138, 0.6505385465131084]
Step 4: Seeing the outputs!
To plot the time series, we can use the actual simulate object directly.
plot(sim, label = ["Producer" "Consumer" "Top consumer";])Eventually you may want to plot the biomass dynamics - the trajectory - of your community to see what is happening. For our minimal example, it can be done as follows:
# create multiple objects: time = t pulled frpom the sim.t component
# and Bx = biomass for each species pulled from the larger sim object
# note how julia allows multiple things on left of the =
t, B1, B2, B3 = sim.t, sim[1,:], sim[2,:], sim[3,:] # unpack variables
# Plot the basal species
plot(t, B1, lw = 3, label="Producer", xlabel = "Time", ylabel = "Biomass")
# add the herbivore
plot!(t, B2, lw = 3, label="Consumer")
# add the top predator
plot!(t, B3, lw = 3, label="Top consumer")A More Complex Example
Step 1: Generate the initial network
In order to run the BEFW model with a more complex network, we have to construct an initial food web network (an adjacency matrix) using the niche model. The network is characterised by the number of species in the network and its connectance/complexity value.
Note that we are now using functionality provided by the EcologicalNetworks package.
S = 20 # define the number of species
C = 0.2 # define the connectance (complexity) of the network
# construct the food web
Random.seed!(12325) # ensures your network and this one are the same
foodweb_niche = Foodweb(:niche; S = S, C = C)
# see it:
foodweb_niche.A20×20 SparseArrays.SparseMatrixCSC{Bool, Int64} with 82 stored entries:
⎡⠉⢉⣉⣉⠀⠀⠰⠤⠄⠀⎤
⎢⠤⠤⠤⢭⣥⣤⡔⠒⠂⠀⎥
⎢⠀⠀⠀⠀⠉⠉⢹⣿⡧⠤⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠸⢤⣄⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠙⠃⎦
Step 2. Setting up the paramters, body masses (species) and running the model!
As above, our next step is to define a vector of bodymasses and then pass this, and the network to the simulate function. Here we combine the Uniform function from the Distributions package with the rand function from the Random package.
# construct the equations and fixed parameters
# see below for body size dependent parameters etc
params_niche = default_model(foodweb_niche)
# define bodymasses between 0 and 1 and get S = 20 of them.
# this will ensure your plot looks like the one in the document
Random.seed!(123)
B0 = rand(S)
t = 300
# simulate using params and bodymasses
# note additional argument tmax for max time steps
# default is 300
sim_niche = simulate(params_niche, B0, t)retcode: Success
Interpolation: 3rd order Hermite
t: 51-element Vector{Float64}:
0.0
0.0983252574499891
0.28544083243480267
0.5267982237043161
0.8245753364604138
1.181896742988936
1.6418353914084878
2.203829100924959
2.893464061893281
3.729699102007749
4.728753111889612
5.890702747756841
7.2218772360496395
⋮
136.70283821576533
145.48441982502288
155.57070934467725
166.67876410920994
179.5612866567586
193.9800038364207
210.21105297520486
227.83156289127072
247.0838336915681
267.94281052881126
290.8959793077713
300.0
u: 51-element Vector{Vector{Float64}}:
[0.906299638797481, 0.44349373245960455, 0.7456733811393941, 0.5120830400366143, 0.2538490889415096, 0.33415153638191886, 0.4273278808735992, 0.867547200255958, 0.09913361484360417, 0.12528740769155033, 0.6922086620547391, 0.13655147513745736, 0.03209667335274724, 0.3505458214588266, 0.9303323763821093, 0.9594335994071538, 0.5819123423876457, 0.3114475007050529, 0.12114752051812694, 0.20452981732035946]
[0.9169483131714715, 0.444402194534041, 0.7667640455857161, 0.5179071161683636, 0.25596644376248334, 0.3439614083570855, 0.42881389580038637, 0.8404857181508336, 0.10207349613818459, 0.12980979255930417, 0.7045585608788062, 0.14142469702894178, 0.033700254458592344, 0.35322775442579823, 0.9254383246584946, 0.8428424981719224, 0.5353929049386887, 0.2716712297929136, 0.11790964375471776, 0.20588623005171253]
[0.9372189186622565, 0.446138581295766, 0.8030805319662981, 0.5280429096670912, 0.25960285298532004, 0.36088969827160805, 0.43143000229873113, 0.7941678141517742, 0.107334065965393, 0.13803877097876832, 0.7224846396419364, 0.150274714852675, 0.03655779055568964, 0.35202356186576755, 0.8867871855452475, 0.6561325211685619, 0.45370991951901846, 0.21879863147029777, 0.1144327890249893, 0.21137607850479412]
[0.963419944890434, 0.4478457678502066, 0.8407656301021255, 0.5394619505769526, 0.26358620538619504, 0.3785307293750754, 0.43443524658702654, 0.7426580903726461, 0.11338938338304744, 0.1475698891121404, 0.7345099631141349, 0.16048747662896795, 0.03959434344670769, 0.3379755377009729, 0.7958692645000881, 0.48283669535781387, 0.36706195693003885, 0.17548000193294144, 0.1136592394878268, 0.22309854306314952]
[0.995616193064571, 0.44805738727466143, 0.8700643195894429, 0.5512240918443782, 0.2674989824178032, 0.3924051349926597, 0.4375425793363201, 0.6886449125246876, 0.11960335804730916, 0.15695502649258633, 0.7327878032629778, 0.17047486846995694, 0.0420936774665965, 0.3062032871443506, 0.6610340292426684, 0.34855000462048347, 0.2881369319293169, 0.14175624955652485, 0.11666389844136492, 0.24243967254676815]
[1.0331366869886944, 0.44448629343725343, 0.8788288901686566, 0.5620901047900512, 0.2708572048035862, 0.39695429480179645, 0.44018298027640984, 0.6333401253753693, 0.1252037789780579, 0.1640984843116221, 0.7114983769875807, 0.17795514254857084, 0.04354809380952039, 0.26092610308891634, 0.5154058541922188, 0.25624511921879434, 0.22330145420147088, 0.11586948470233616, 0.12436895504970236, 0.26962910331924905]
[1.0773089982155897, 0.43396923698721435, 0.8556572961992899, 0.5707904139404543, 0.2731983214483226, 0.38705755776238965, 0.4413794083264426, 0.57197930814629, 0.12978003467017415, 0.16724868374246712, 0.6675169557355778, 0.18101017312972054, 0.04388752925907648, 0.20909394578211202, 0.3805309865842198, 0.19230727005942244, 0.16943175281775166, 0.09443672996682428, 0.13906102138589269, 0.30741066949967055]
[1.1213743703927337, 0.4149870885160012, 0.7975741540831984, 0.5733620864984142, 0.2733077885606147, 0.36141676843558873, 0.4391552288251882, 0.5071960218562799, 0.13225598133704913, 0.1649144766546638, 0.6093837906327526, 0.17807037605762552, 0.04315159765633695, 0.1631734536430942, 0.2790930366914647, 0.15237925689592774, 0.12890880773111002, 0.0777317468581009, 0.16225155189984958, 0.35425475261372863]
[1.1573410183305781, 0.3875799067335869, 0.7122633234623346, 0.5656661531044221, 0.2699342224158771, 0.32362037390928877, 0.43151833519945715, 0.43980122366299085, 0.1320832740044849, 0.15754833392958092, 0.5485937790090555, 0.16967851768901068, 0.04155688582593655, 0.12670961646818607, 0.20790093579654878, 0.12919220653556573, 0.09920527144448085, 0.06511083602693121, 0.1957265685332169, 0.40863184877785175]
[1.1744909386178761, 0.35353525150930704, 0.6130415990319116, 0.5442924204781258, 0.2619765432579562, 0.2797239154423789, 0.41725964546931765, 0.3734718885747243, 0.12906194711831975, 0.14648620822639452, 0.49617455885534983, 0.15734180901650238, 0.039351964038387546, 0.0993990767009241, 0.15977668195469585, 0.1193453433823383, 0.07853078787521317, 0.05684848395648957, 0.23880211323157663, 0.46473430625333423]
[1.1636651009007108, 0.3155425241026375, 0.5129043599973696, 0.5086210124289895, 0.24908969960788688, 0.23553191470443982, 0.3966456636545259, 0.3124900352369809, 0.12355869405172261, 0.13330212010711523, 0.45885425946835634, 0.14280589051662543, 0.036833828434965285, 0.07940681588029759, 0.1280065867800307, 0.12159259236413968, 0.06534238144397321, 0.053601952458352684, 0.28528412637082984, 0.5126103913127859]
[1.1215900120487023, 0.2768216752264026, 0.42206636648520485, 0.46189135063482056, 0.23215126320140814, 0.19551978933588599, 0.37144587200796514, 0.26042387609908113, 0.11647562742120145, 0.11955373899209087, 0.4381554894529827, 0.1277697315605396, 0.034397853577932694, 0.06512710102028911, 0.10768752758342186, 0.13551750917697, 0.058102384679568894, 0.055907692857973916, 0.3220846544335181, 0.5412432565515389]
[1.051674472438156, 0.2396400556460993, 0.34499392466732914, 0.408962875223587, 0.21264909765819076, 0.16158429863184295, 0.3435589630316772, 0.2180232510648064, 0.10878792457246415, 0.10632571872188118, 0.43013574616355804, 0.11339063974249527, 0.03248700163555598, 0.055268908325187105, 0.0946316891444375, 0.1595784203240174, 0.05459709129704919, 0.0631635952778267, 0.33753068620574334, 0.5455404467088186]
⋮
[0.00032755644980272486, 0.00042642730013303957, 0.00024189593390109746, 3.1111688980955344e-5, 0.002186365444974394, 0.0001284836050334962, 0.009392611128074742, 0.2289263661082618, 0.027817843518977224, 0.00011632790937708126, 0.4448717546882417, 0.0001223774188672115, 0.198564855194196, 0.09669339044487263, 0.041438780171243736, 0.21624377256231636, 0.010260398961170272, 0.1106446052574405, 0.30895191650548376, 0.48344362584850714]
[0.0001996798247022266, 0.0003009378761392906, 0.00015346749983007282, 1.8190449427202614e-5, 0.0017884347223449826, 8.151473534424173e-5, 0.0077101296606787864, 0.23181199431785626, 0.025313811373776522, 7.379449257908107e-5, 0.44476144744230767, 7.763164111187508e-5, 0.19771575290544488, 0.0981753484444294, 0.0415237986113816, 0.21618611797874981, 0.010096001729578499, 0.1107711243020971, 0.3089588621965838, 0.4835526097023227]
[0.00011328126257715799, 0.0002025145740727682, 9.102676275323986e-5, 9.86615934389697e-6, 0.0014273867429624918, 4.834918126253599e-5, 0.006152674701416408, 0.2345821350465174, 0.022777702555973164, 4.3766536607882777e-5, 0.44485825775398713, 4.604210489119089e-5, 0.19677603845677671, 0.0996135511824476, 0.04163063947534051, 0.21611456663905765, 0.00992313898370846, 0.1108762739174712, 0.30896257460215903, 0.4836121681503955]
[6.07969185813491e-5, 0.00013150891522278353, 5.122984902532575e-5, 5.0559263528295375e-6, 0.0011197509119850043, 2.721092248119792e-5, 0.004805123705498752, 0.2371493862104039, 0.02034698607033935, 2.4630532478594332e-5, 0.44507776580317365, 2.591108561516969e-5, 0.19582059389086015, 0.10090484291104647, 0.04175110898630074, 0.21605866945798072, 0.009748297718843965, 0.1109547748500005, 0.308965762906422, 0.48361873148098766]
[2.9540113221979872e-5, 8.00347447973086e-5, 2.6268553079549285e-5, 2.3358462951272875e-6, 0.0008502538978690424, 1.3952641028662382e-5, 0.0036125895986525765, 0.23963412412998863, 0.017924696653654346, 1.2629101514971793e-5, 0.4453417610345992, 1.3285671319358326e-5, 0.19486664345382582, 0.10209874101875081, 0.041891604062307145, 0.2160237975426658, 0.00956208380761516, 0.11101835580249045, 0.3089707135225891, 0.48359145640506035]
[1.3166616427449579e-5, 4.60961582614326e-5, 1.241859399595492e-5, 9.875013357564836e-7, 0.0006289434801525733, 6.596183545884943e-6, 0.0026293723865516917, 0.24190491545204867, 0.015626334170708748, 5.970359692556319e-6, 0.44560575498650923, 6.280744324641365e-6, 0.19400924653479448, 0.10314206416955765, 0.04204857588531362, 0.2160007866180423, 0.009371522869382096, 0.11107366457263641, 0.3089769794039354, 0.48355133078668755]
[5.288582093742206e-6, 2.4853056623534485e-5, 5.32431964558186e-6, 3.7495755123700837e-7, 0.0004510237192764804, 2.8280327624688987e-6, 0.0018418173438047715, 0.24395924306889033, 0.013458321791607284, 2.559692577943294e-6, 0.44587256631997335, 2.692763414898462e-6, 0.19326957086896235, 0.10403490013949204, 0.04222157762263886, 0.21597907364688387, 0.009176377022194124, 0.11112583015368675, 0.30898347361961076, 0.4835073952384332]
[1.960571333984018e-6, 1.2748386630159753e-5, 2.115911956181734e-6, 1.3122771778296083e-7, 0.00031649230625780636, 1.1238747466059242e-6, 0.0012535673852407435, 0.2457433105385709, 0.011504652249667801, 1.0172301703560636e-6, 0.44612733302168156, 1.0701126911743665e-6, 0.19267165202271308, 0.1047507539103007, 0.04240100704365944, 0.21595925499391128, 0.008984468602875842, 0.11117426849212075, 0.30898978378818076, 0.48346305093339226]
[6.595296475377276e-7, 6.157495485353746e-6, 7.673573735587585e-7, 4.1573174269355544e-8, 0.0002163095240186386, 4.0758481170993133e-7, 0.0008246351715236552, 0.24730063052972948, 0.009744807150823888, 3.6890828571649465e-7, 0.4463589658982419, 3.880865976484553e-7, 0.19219749029253488, 0.10531819548561512, 0.042584771757986466, 0.21594251593637606, 0.008795235529894242, 0.11122083597743129, 0.3089962400343031, 0.48342085434013]
[2.0108052810226762e-7, 2.8004575219465937e-6, 2.5369560293790977e-7, 1.190656631256341e-8, 0.00014408987057401768, 1.3475139250220505e-7, 0.0005246117248146955, 0.24864251960077316, 0.008183727277329841, 1.2196446538994685e-7, 0.4465625705694917, 1.2830498581813105e-7, 0.19183327165148306, 0.10575941597710509, 0.04276848561656389, 0.21592768854223388, 0.008611086962690943, 0.11126649455166937, 0.30900276016604544, 0.4833835692529364]
[5.35850498787597e-8, 1.174593201709331e-6, 7.398752912499898e-8, 2.965192061208363e-9, 9.266705935747393e-5, 3.929875986723788e-8, 0.00031929137827090367, 0.24981133030734196, 0.006788855740405869, 3.556958190340493e-8, 0.4467437607797747, 3.7418723667047955e-8, 0.19155285868338037, 0.10610455981258715, 0.04295191471606665, 0.21591384077514106, 0.008430160333184566, 0.1113122756892104, 0.30900934087551246, 0.48335082223348647]
[3.2821854904203205e-8, 8.406671643638472e-7, 4.6640508998017896e-8, 1.7793663607263053e-9, 7.799523091116062e-5, 2.4773285240091262e-8, 0.0002627973314424048, 0.2502039748903548, 0.00631276636245039, 2.2422472598477954e-8, 0.4468055436036614, 2.358814075481337e-8, 0.19146688286657296, 0.10621159455428622, 0.04301932407939025, 0.21590899888568155, 0.008364030293673712, 0.11132929056683419, 0.3090117977250657, 0.4833397504740079]
Step 3. Visualising the dynamics
Now we can move to plotting again. Note how we now ask for the time directly from the simulate object and all of the biomasses from that object as well.
Note too how we can supress the legend (which covers some of the time series).
plot(sim_niche, legend = false)One game to play now is to alter the bodymass distribution. rand selects a randon uniform number between 0 and 1. Can you figure out how to make the distribution uniform between 0 and 10? See what that does.
A bit more about the process: dissecting the ModelParameters
Let’s dissect the ModelParameters object a bit, to understand just a bit more about what is going on.
params_nicheModel (alias for EcologicalNetworksDynamics.Framework.System{<inner parms>}) with 17 components:
- Species: 20 (:s1, :s2, :s3, :s4, ..., :s20)
- Foodweb: 82 links
- Body masses: [396.6757314506745, 1000.0, 138.23722273578997, 150.62580571223663, ..., 1.0]
- Metabolic classes: [:invertebrate, :invertebrate, :invertebrate, :invertebrate, ..., :producer]
- GrowthRate: [·, ·, ·, ·, ..., 1.0]
- Carrying capacity: [·, ·, ·, ·, ..., 1.0]
- ProducersCompetition: 1.0
- LogisticGrowth
- Efficiency: 0.45 to 0.85.
- MaximumConsumption: [8.0, 8.0, 8.0, 8.0, ..., ·]
- Hill exponent: 2.0
- Consumers preferences: 0.07692307692307693 to 1.0.
- Intra-specific interference: [·, ·, ·, ·, ..., ·]
- Half-saturation density: [0.5, 0.5, 0.5, 0.5, ..., ·]
- BioenergeticResponse
- Metabolism: [0.0703591752903408, 0.05583797347522218, 0.09157425582526797, 0.08963029015067063, ..., 0.0]
- Mortality: [0.0, 0.0, 0.0, 0.0, ..., 0.0]
Walking through this
- The
networkcomponent defines the food web and reports the number of species and the links - the
environmentcomponent reports on values of the carrying capacity (K) and the baseline temperature (T). Note that K is specified only for the basal species via[1, 1, ... nothing, nothing]. All the producers have the same K at this point (1,1,1…). The presence of theTsuggests that we can ultimately work with climate change by running the model at different temperatures. There is a way to make some of the biorates and components of the functional response (see 3, 4) dependent not only on body mass, but also on temperature. - the
bioratescomponent contains detail on parameters central to making the model reflect a bit of reality:dis …;ris the intrinsic rate of increase (population growth rate) for the producers (plants);xandyare paramters associated with metabolic rates and consumption rates of the consumers (non-plant species). Finally,eis an efficiency/assimilation rate for the consumers eating either plants or other animals. - the
functional_responsecomponent defines the type of consumption function being used (e.g. Type I, II, or III sensu classic ecology and Holling). The functional response defines the interaction strength between species and how consumers change how much they eat dependent on the amount (density) of resource available.There are two options. The defaultBioenergetic Responsecorresponds to a phenomenological formulation where there are just two variables that describe how consumer consumption varies with resource density: a half-saturation parameter and an asymptote. The alternative calledClassic Responseis more trait based and includes the parameters attack rate and handling time. There are several other features of the functional response that can be manipulated, and these are introduced in later tutorials. - the
producer_growthdetails the default that all plants are growing logistically. - the
temperature responsecomponewnt defines the absence or presence of temperature dependence, and when present, the shape of the relationship between biorates and functional response parameters and temperature.
Helper Functions: What can we do with the outputs?
As noted in the pre-amble, we are most often interested in additional information about the scenarios we build with the models. These include, for example, total biomass, biodiversity and stability. Let’s see how we can calcuate some of these.
How long till steady state?
We can find out how long the simulations ran to reach steady state - remember that this is a deterministic model that typicall reaches equilibrium for all species that survive.
size(sim_niche.t)(51,)
Who went extinct and when?
We can also find out who went extinct, and when. You saw some of that detail, I hope, in the output of simulate.
get_extinct_species(sim_niche)Biomass, Diversity and Stability
First, we can get a measure of total biomass in the community, at equilibrium, and that of each species. Note how you can get the components too.
sim_niche.u51-element Vector{Vector{Float64}}:
[0.906299638797481, 0.44349373245960455, 0.7456733811393941, 0.5120830400366143, 0.2538490889415096, 0.33415153638191886, 0.4273278808735992, 0.867547200255958, 0.09913361484360417, 0.12528740769155033, 0.6922086620547391, 0.13655147513745736, 0.03209667335274724, 0.3505458214588266, 0.9303323763821093, 0.9594335994071538, 0.5819123423876457, 0.3114475007050529, 0.12114752051812694, 0.20452981732035946]
[0.9169483131714715, 0.444402194534041, 0.7667640455857161, 0.5179071161683636, 0.25596644376248334, 0.3439614083570855, 0.42881389580038637, 0.8404857181508336, 0.10207349613818459, 0.12980979255930417, 0.7045585608788062, 0.14142469702894178, 0.033700254458592344, 0.35322775442579823, 0.9254383246584946, 0.8428424981719224, 0.5353929049386887, 0.2716712297929136, 0.11790964375471776, 0.20588623005171253]
[0.9372189186622565, 0.446138581295766, 0.8030805319662981, 0.5280429096670912, 0.25960285298532004, 0.36088969827160805, 0.43143000229873113, 0.7941678141517742, 0.107334065965393, 0.13803877097876832, 0.7224846396419364, 0.150274714852675, 0.03655779055568964, 0.35202356186576755, 0.8867871855452475, 0.6561325211685619, 0.45370991951901846, 0.21879863147029777, 0.1144327890249893, 0.21137607850479412]
[0.963419944890434, 0.4478457678502066, 0.8407656301021255, 0.5394619505769526, 0.26358620538619504, 0.3785307293750754, 0.43443524658702654, 0.7426580903726461, 0.11338938338304744, 0.1475698891121404, 0.7345099631141349, 0.16048747662896795, 0.03959434344670769, 0.3379755377009729, 0.7958692645000881, 0.48283669535781387, 0.36706195693003885, 0.17548000193294144, 0.1136592394878268, 0.22309854306314952]
[0.995616193064571, 0.44805738727466143, 0.8700643195894429, 0.5512240918443782, 0.2674989824178032, 0.3924051349926597, 0.4375425793363201, 0.6886449125246876, 0.11960335804730916, 0.15695502649258633, 0.7327878032629778, 0.17047486846995694, 0.0420936774665965, 0.3062032871443506, 0.6610340292426684, 0.34855000462048347, 0.2881369319293169, 0.14175624955652485, 0.11666389844136492, 0.24243967254676815]
[1.0331366869886944, 0.44448629343725343, 0.8788288901686566, 0.5620901047900512, 0.2708572048035862, 0.39695429480179645, 0.44018298027640984, 0.6333401253753693, 0.1252037789780579, 0.1640984843116221, 0.7114983769875807, 0.17795514254857084, 0.04354809380952039, 0.26092610308891634, 0.5154058541922188, 0.25624511921879434, 0.22330145420147088, 0.11586948470233616, 0.12436895504970236, 0.26962910331924905]
[1.0773089982155897, 0.43396923698721435, 0.8556572961992899, 0.5707904139404543, 0.2731983214483226, 0.38705755776238965, 0.4413794083264426, 0.57197930814629, 0.12978003467017415, 0.16724868374246712, 0.6675169557355778, 0.18101017312972054, 0.04388752925907648, 0.20909394578211202, 0.3805309865842198, 0.19230727005942244, 0.16943175281775166, 0.09443672996682428, 0.13906102138589269, 0.30741066949967055]
[1.1213743703927337, 0.4149870885160012, 0.7975741540831984, 0.5733620864984142, 0.2733077885606147, 0.36141676843558873, 0.4391552288251882, 0.5071960218562799, 0.13225598133704913, 0.1649144766546638, 0.6093837906327526, 0.17807037605762552, 0.04315159765633695, 0.1631734536430942, 0.2790930366914647, 0.15237925689592774, 0.12890880773111002, 0.0777317468581009, 0.16225155189984958, 0.35425475261372863]
[1.1573410183305781, 0.3875799067335869, 0.7122633234623346, 0.5656661531044221, 0.2699342224158771, 0.32362037390928877, 0.43151833519945715, 0.43980122366299085, 0.1320832740044849, 0.15754833392958092, 0.5485937790090555, 0.16967851768901068, 0.04155688582593655, 0.12670961646818607, 0.20790093579654878, 0.12919220653556573, 0.09920527144448085, 0.06511083602693121, 0.1957265685332169, 0.40863184877785175]
[1.1744909386178761, 0.35353525150930704, 0.6130415990319116, 0.5442924204781258, 0.2619765432579562, 0.2797239154423789, 0.41725964546931765, 0.3734718885747243, 0.12906194711831975, 0.14648620822639452, 0.49617455885534983, 0.15734180901650238, 0.039351964038387546, 0.0993990767009241, 0.15977668195469585, 0.1193453433823383, 0.07853078787521317, 0.05684848395648957, 0.23880211323157663, 0.46473430625333423]
[1.1636651009007108, 0.3155425241026375, 0.5129043599973696, 0.5086210124289895, 0.24908969960788688, 0.23553191470443982, 0.3966456636545259, 0.3124900352369809, 0.12355869405172261, 0.13330212010711523, 0.45885425946835634, 0.14280589051662543, 0.036833828434965285, 0.07940681588029759, 0.1280065867800307, 0.12159259236413968, 0.06534238144397321, 0.053601952458352684, 0.28528412637082984, 0.5126103913127859]
[1.1215900120487023, 0.2768216752264026, 0.42206636648520485, 0.46189135063482056, 0.23215126320140814, 0.19551978933588599, 0.37144587200796514, 0.26042387609908113, 0.11647562742120145, 0.11955373899209087, 0.4381554894529827, 0.1277697315605396, 0.034397853577932694, 0.06512710102028911, 0.10768752758342186, 0.13551750917697, 0.058102384679568894, 0.055907692857973916, 0.3220846544335181, 0.5412432565515389]
[1.051674472438156, 0.2396400556460993, 0.34499392466732914, 0.408962875223587, 0.21264909765819076, 0.16158429863184295, 0.3435589630316772, 0.2180232510648064, 0.10878792457246415, 0.10632571872188118, 0.43013574616355804, 0.11339063974249527, 0.03248700163555598, 0.055268908325187105, 0.0946316891444375, 0.1595784203240174, 0.05459709129704919, 0.0631635952778267, 0.33753068620574334, 0.5455404467088186]
⋮
[0.00032755644980272486, 0.00042642730013303957, 0.00024189593390109746, 3.1111688980955344e-5, 0.002186365444974394, 0.0001284836050334962, 0.009392611128074742, 0.2289263661082618, 0.027817843518977224, 0.00011632790937708126, 0.4448717546882417, 0.0001223774188672115, 0.198564855194196, 0.09669339044487263, 0.041438780171243736, 0.21624377256231636, 0.010260398961170272, 0.1106446052574405, 0.30895191650548376, 0.48344362584850714]
[0.0001996798247022266, 0.0003009378761392906, 0.00015346749983007282, 1.8190449427202614e-5, 0.0017884347223449826, 8.151473534424173e-5, 0.0077101296606787864, 0.23181199431785626, 0.025313811373776522, 7.379449257908107e-5, 0.44476144744230767, 7.763164111187508e-5, 0.19771575290544488, 0.0981753484444294, 0.0415237986113816, 0.21618611797874981, 0.010096001729578499, 0.1107711243020971, 0.3089588621965838, 0.4835526097023227]
[0.00011328126257715799, 0.0002025145740727682, 9.102676275323986e-5, 9.86615934389697e-6, 0.0014273867429624918, 4.834918126253599e-5, 0.006152674701416408, 0.2345821350465174, 0.022777702555973164, 4.3766536607882777e-5, 0.44485825775398713, 4.604210489119089e-5, 0.19677603845677671, 0.0996135511824476, 0.04163063947534051, 0.21611456663905765, 0.00992313898370846, 0.1108762739174712, 0.30896257460215903, 0.4836121681503955]
[6.07969185813491e-5, 0.00013150891522278353, 5.122984902532575e-5, 5.0559263528295375e-6, 0.0011197509119850043, 2.721092248119792e-5, 0.004805123705498752, 0.2371493862104039, 0.02034698607033935, 2.4630532478594332e-5, 0.44507776580317365, 2.591108561516969e-5, 0.19582059389086015, 0.10090484291104647, 0.04175110898630074, 0.21605866945798072, 0.009748297718843965, 0.1109547748500005, 0.308965762906422, 0.48361873148098766]
[2.9540113221979872e-5, 8.00347447973086e-5, 2.6268553079549285e-5, 2.3358462951272875e-6, 0.0008502538978690424, 1.3952641028662382e-5, 0.0036125895986525765, 0.23963412412998863, 0.017924696653654346, 1.2629101514971793e-5, 0.4453417610345992, 1.3285671319358326e-5, 0.19486664345382582, 0.10209874101875081, 0.041891604062307145, 0.2160237975426658, 0.00956208380761516, 0.11101835580249045, 0.3089707135225891, 0.48359145640506035]
[1.3166616427449579e-5, 4.60961582614326e-5, 1.241859399595492e-5, 9.875013357564836e-7, 0.0006289434801525733, 6.596183545884943e-6, 0.0026293723865516917, 0.24190491545204867, 0.015626334170708748, 5.970359692556319e-6, 0.44560575498650923, 6.280744324641365e-6, 0.19400924653479448, 0.10314206416955765, 0.04204857588531362, 0.2160007866180423, 0.009371522869382096, 0.11107366457263641, 0.3089769794039354, 0.48355133078668755]
[5.288582093742206e-6, 2.4853056623534485e-5, 5.32431964558186e-6, 3.7495755123700837e-7, 0.0004510237192764804, 2.8280327624688987e-6, 0.0018418173438047715, 0.24395924306889033, 0.013458321791607284, 2.559692577943294e-6, 0.44587256631997335, 2.692763414898462e-6, 0.19326957086896235, 0.10403490013949204, 0.04222157762263886, 0.21597907364688387, 0.009176377022194124, 0.11112583015368675, 0.30898347361961076, 0.4835073952384332]
[1.960571333984018e-6, 1.2748386630159753e-5, 2.115911956181734e-6, 1.3122771778296083e-7, 0.00031649230625780636, 1.1238747466059242e-6, 0.0012535673852407435, 0.2457433105385709, 0.011504652249667801, 1.0172301703560636e-6, 0.44612733302168156, 1.0701126911743665e-6, 0.19267165202271308, 0.1047507539103007, 0.04240100704365944, 0.21595925499391128, 0.008984468602875842, 0.11117426849212075, 0.30898978378818076, 0.48346305093339226]
[6.595296475377276e-7, 6.157495485353746e-6, 7.673573735587585e-7, 4.1573174269355544e-8, 0.0002163095240186386, 4.0758481170993133e-7, 0.0008246351715236552, 0.24730063052972948, 0.009744807150823888, 3.6890828571649465e-7, 0.4463589658982419, 3.880865976484553e-7, 0.19219749029253488, 0.10531819548561512, 0.042584771757986466, 0.21594251593637606, 0.008795235529894242, 0.11122083597743129, 0.3089962400343031, 0.48342085434013]
[2.0108052810226762e-7, 2.8004575219465937e-6, 2.5369560293790977e-7, 1.190656631256341e-8, 0.00014408987057401768, 1.3475139250220505e-7, 0.0005246117248146955, 0.24864251960077316, 0.008183727277329841, 1.2196446538994685e-7, 0.4465625705694917, 1.2830498581813105e-7, 0.19183327165148306, 0.10575941597710509, 0.04276848561656389, 0.21592768854223388, 0.008611086962690943, 0.11126649455166937, 0.30900276016604544, 0.4833835692529364]
[5.35850498787597e-8, 1.174593201709331e-6, 7.398752912499898e-8, 2.965192061208363e-9, 9.266705935747393e-5, 3.929875986723788e-8, 0.00031929137827090367, 0.24981133030734196, 0.006788855740405869, 3.556958190340493e-8, 0.4467437607797747, 3.7418723667047955e-8, 0.19155285868338037, 0.10610455981258715, 0.04295191471606665, 0.21591384077514106, 0.008430160333184566, 0.1113122756892104, 0.30900934087551246, 0.48335082223348647]
[3.2821854904203205e-8, 8.406671643638472e-7, 4.6640508998017896e-8, 1.7793663607263053e-9, 7.799523091116062e-5, 2.4773285240091262e-8, 0.0002627973314424048, 0.2502039748903548, 0.00631276636245039, 2.2422472598477954e-8, 0.4468055436036614, 2.358814075481337e-8, 0.19146688286657296, 0.10621159455428622, 0.04301932407939025, 0.21590899888568155, 0.008364030293673712, 0.11132929056683419, 0.3090117977250657, 0.4833397504740079]
# components
total_biomass(sim_niche)51-element Vector{Float64}:
9.035052310145453
8.879184522388458
8.608521978391984
8.302235859798492
7.977752408265428
7.6479265310498565
7.293056293658903
6.933942335839723
6.569662630859385
6.203645482991124
5.835689949822736
5.4639327723474995
5.082524806480722
⋮
2.180830466139856
2.179270649906686
2.177861954789722
2.1766481390536
2.1755648676013255
2.174661007473904
2.1739250919601236
2.1733597626038192
2.1729302781639843
2.1726139439247745
2.172383095801758
2.172315739557126
Second, we can an estimate of species persistence - how many have gone extinct! Remember that we started with 20, so a value of 0.45 means that there are 12 species left.
# the percentage that persist
persistence(sim_niche)51-element Vector{Float64}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
⋮
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
# quick calculation of number left (but see richness below!)
20*persistence(sim_niche) # the numbner left51-element Vector{Float64}:
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
⋮
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
20.0
Third, we can look at measures of diversity. First, we can get species richness and a measure of diversity, using the Shannon index. This confirms that our persistence estimate (45%) is in line!
richness(sim_niche)51-element Vector{Int64}:
20
20
20
20
20
20
20
20
20
20
20
20
20
⋮
20
20
20
20
20
20
20
20
20
20
20
20
shannon_diversity(sim_niche)51-element Vector{Float64}:
15.838289686150633
15.938034479922063
16.062630873979742
16.120434078447378
16.08114076965578
15.938487296717936
15.697940272210305
15.410182133499104
15.107012611506958
14.810310060152338
14.548540861111752
14.364162310889597
14.284610563485106
⋮
8.172811865080977
8.1142305814134
8.05780958633494
8.006127953781233
7.956790341905648
7.911831829238024
7.87087151813162
7.835016456582986
7.803489117438748
7.776056823831216
7.751865699167424
7.743665633968
Finally, we can look at stability - all built in metrics of stability are based on the coefficient of variation of species biomass. The CV is a measure of standardised variation - the standard deviation / mean (https://en.wikipedia.org/wiki/Coefficient_of_variation). It is not ‘stability’ in the strict mathematical sense, but an estimation of how variable the dynamics are.
defined as the average coefficient of variation estimated across all of the coefficients of variation for each species.
The master function is coefficient_of_variation and delivers four results - Coefficient of Variation (CV) of community biomass and its partition into average species CV (community_cv above), species mean CV and synchrony, along with the variation of each species; following Thibault & Connolly (2013):
coefficient_of_variation(sim_niche)Note the warning…. do you understand what it’s talking about? Think about the extinctions detail above. You can follow the instructions, right?
coefficient_of_variation(sim_niche, last = 4)You can get parts of this with specific helper functions, such as:
community_cv(sim_niche, last = 4)What’s next
The next section will introduce how to create simulations where we work with multiple networks and collect data across these. We do this using loops, and collect information in a data frame. We then work on how to embed additional changes to parameters in the loops as well.